package com.person.jiaiplan.contant;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import lombok.Getter;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

@Getter
public enum ConstGroupEnum {

    //这个最外层组
    CONSTGROUP("constGroup", "constGroup_", "下拉词条分组", 0),
    CONSTGROUP_OPERATOR_TYPE("constgroup_", "constgroup_operator_type", "计划类型", 0),
    CONSTGROUP_OPERATOR_TYPE_0("constgroup_operator_type", 1, "工作", 1),
    CONSTGROUP_OPERATOR_TYPE_1("constgroup_operator_type", 2, "生活", 2),
    CONSTGROUP_OPERATOR_TYPE_2("constgroup_operator_type", 3, "学习", 3),
    CONSTGROUP_PLAN_TYPE("constgroup_", "constgroup_plan_type", "计划状态", 0),
    CONSTGROUP_PLAN_TYPE_0("constgroup_plan_type", 1, "临时计划", 1),
    CONSTGROUP_PLAN_TYPE_1("constgroup_plan_type", 2, "短期计划", 2),
    CONSTGROUP_PLAN_TYPE_2("constgroup_plan_type", 3, "长期计划", 3),
    CONSTGROUP_PLAN_RULES("constgroup_", "constgroup_plan_rules", "计划规则", 0),
    CONSTGROUP_PLAN_RULES_0("constgroup_plan_rules", 1, "每周", 1),
    CONSTGROUP_PLAN_RULES_1("constgroup_plan_rules", 2, "间隔日", 2),
    CONSTGROUP_PLAN_RULES_2("constgroup_plan_rules", 3, "指定日期", 3),
    CONST_GROUP_TODAY_CHECK_IN("constgroup_", "constgroup_today_clockin", "今日打卡", 0),
    CONST_GROUP_TODAY_CHECK_IN_0("constgroup_today_clockin", 1, "已打卡", 1),
    CONST_GROUP_TODAY_CHECK_IN_1("constgroup_today_clockin", 2, "需打卡", 2),
    CONST_GROUP_TODAY_CHECK_IN_2("constgroup_today_clockin", 3, "不需打卡", 3),
    CONST_GROUP_TODAY_CHECK_IN_3("constgroup_today_clockin", "4", "补卡", 4),
    CONST_GROUP_PLAN_STATUS("constgroup_", "constgroup_plan_status", "计划状态", 0),
    CONST_GROUP_PLAN_STATUS_0("constgroup_plan_status", 1, "进行中", 1),
    CONST_GROUP_PLAN_STATUS_1("constgroup_plan_status", 2, "已完成", 2),
    CONST_GROUP_PLAN_STATUS_2("constgroup_plan_status", 3, "已放弃", 3),
    CONST_GROUP_EXPENSES_TYPE("constgroup_", "constgroup_expenses_type", "花销类型", 0),
    CONST_GROUP_EXPENSES_TYPE_0("constgroup_expenses_type", 1, "每日", 1),
    CONST_GROUP_EXPENSES_TYPE_1("constgroup_expenses_type", 2, "分期", 2),
    CONST_GROUP_EXPENSES_TYPE_2("constgroup_expenses_type", 3, "计划", 3),
    CONST_GROUP_EXPENSES_TYPE_3("constgroup_expenses_type", 4, "奖励", 4),
    CONST_GROUP_EXPENSES_TYPE_4("constgroup_expenses_type", 5, "会员", 5),
    CONST_GROUP_EXPENSES_TYPE_5("constgroup_expenses_type", 6, "冲动消费", 6),
    CONST_GROUP_EXPENSES_TYPE_6("constgroup_expenses_type", 7, "其他", 7),
    CONST_GROUP_ACCOUNT_TYPE("constgroup_", "constgroup_account_type", "账户类型", 0),
    CONST_GROUP_ACCOUNT_TYPE_0("constgroup_account_type", 1, "普通会员", 1),
    CONST_GROUP_ACCOUNT_TYPE_1("constgroup_account_type", 2, "月会员", 2),
    CONST_GROUP_ACCOUNT_TYPE_2("constgroup_account_type", 3, "季度会员", 3),
    CONST_GROUP_ACCOUNT_TYPE_3("constgroup_account_type", 4, "年会员", 4),
    CONST_GROUP_ACCOUNT_TYPE_4("constgroup_account_type", 5, "续费会员", 5),
    CONST_GROUP_ACCOUNT_TYPE_5("constgroup_account_type", 6, "永久会员", 6),
    CONST_GROUP_COMMEMORATION_TYPE("constgroup_", "constgroup_commemoration_type", "纪念日类型", 0),
    CONST_GROUP_COMMEMORATION_TYPE_0("constgroup_commemoration_type", 1, "一年一次", 1),
    CONST_GROUP_COMMEMORATION_TYPE_1("constgroup_commemoration_type", 2, "一月一次", 2),
    CONST_GROUP_COMMEMORATION_TYPE_2("constgroup_commemoration_type", 3, "一次", 3),
    CONSTGROUP_END("constGroup_", "constGroup_end", "下拉词条分组结束", 0);


    public static final Map<String, Map<String, Object>> map = new HashMap<>();

    /**
     * 初始化map,key 举例:constGroup_release_status_str_2
     */
    static {
        Map<String, Object> mapItem = new LinkedHashMap<>();
        String key = "";
        for (ConstGroupEnum item : ConstGroupEnum.values()) {
            String mapKey = getMapKey(item);
            if (mapKey != null) {
                if (StringUtils.isNotBlank(String.valueOf(key))) {
                    map.put(key, mapItem);

                }
                mapItem = new LinkedHashMap<>();
                key = mapKey;

            } else {
                mapItem.put(item.getExplain(), item.getItemValue());

            }

        }
    }

    /**
     * 分组
     */
    private String constGroup;
    /**
     * 值
     */
    private Object itemValue;
    /**
     * 解释
     */
    private String explain;
    /**
     * 排序
     */
    private Integer sort;

    ConstGroupEnum(String constGroup, Object itemValue, String explain, Integer sort) {
        this.constGroup = constGroup;
        this.itemValue = itemValue;
        this.explain = explain;
        this.sort = sort;
    }

    /**
     * 获取视图的key
     *
     * @param item
     * @return
     */
    public static String getMapKey(ConstGroupEnum item) {
        if (item.getConstGroup().endsWith("_")) {
            return String.valueOf(item.getItemValue());
        }
        return null;
    }


}
